package com.example.student_systeam.controller;

import com.example.student_systeam.common.Result;
import com.example.student_systeam.entity.Student;
import com.example.student_systeam.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
//import javax.annotation.Resource;

@CrossOrigin
@RequestMapping("/student")
@RestController
public class StudentController {

    @Autowired
    StudentService studentService;


    @RequestMapping("/findAllStudent")
    public Result findAllStudent(){
//        System.out.println("接收到了请求");
        return Result.success(studentService.findAllStudent());
    }

    @PostMapping("/insertStudent")
    @ResponseBody
    public Result insertStudent(@RequestBody Student student){
        studentService.insertStudent(student);
        return Result.success("插入成功");
    }

    @PutMapping("/updateStudent")
    @ResponseBody
    public Result updateStudent(@RequestBody Student student){
        studentService.updateStudent(student);
        return Result.success("修改成功");
    }

    @PostMapping("/deleteStudent")
    @ResponseBody
    public Result deleteStudentByName(@RequestBody Student student){
        studentService.deleteStudentByName(student);
        return Result.success("删除成功");
    }


}
